package es.uoc.mxpdroid.ihm;

import com.example.mxpdroid.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;

public class ListActivity extends Activity {
	
	public static final String SURFACES_AVAILABLE = "surfaceAvailables";
	
	private CharSequence[] surfaces;
	
	public static final String SURFACE	=	"surface";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list);
		// Show the Up button in the action bar.
		setupActionBar();
		
		//getting extra data from intent that started this current activity
		Intent sender = getIntent();
		surfaces = sender.getCharSequenceArrayExtra(ListActivity.SURFACES_AVAILABLE);
		
		int[] ids = {R.id.radio0, R.id.radio1, R.id.radio2, R.id.radio3, R.id.radio4,
				R.id.radio5, R.id.radio6, R.id.radio7, R.id.radio8, R.id.radio9};
		
		for(int ii = 0; ii < surfaces.length; ii++){
			RadioButton rb = (RadioButton)findViewById(ids[ii]);
			rb.setText(surfaces[ii]);
		}
	}

	/**
	 * Set up the {@link android.app.ActionBar}, if the API is available.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}
	
	public void selectLayer(View vv){
		int n_surface = -1;
		RadioGroup rg=(RadioGroup)findViewById(R.id.radioGroupLayers);
		int id = rg.getCheckedRadioButtonId();
		
		switch(id){
		case R.id.radio0:
			n_surface = 0;
			break;
		case R.id.radio1:
			n_surface = 1;
			break;
		case R.id.radio2:
			n_surface = 2;
			break;
		case R.id.radio3:
			n_surface = 3;
			break;
		case R.id.radio4:
			n_surface = 4;
			break;
		case R.id.radio5:
			n_surface = 5;
			break;
		case R.id.radio6:
			n_surface = 6;
			break;
		case R.id.radio7:
			n_surface = 7;
			break;
		case R.id.radio8:
			n_surface = 8;
			break;
		case R.id.radio9:
			n_surface = 9;
			break;
		}
		
		Intent intent = new Intent();
		intent.putExtra(ListActivity.SURFACE, n_surface);
		setResult(RESULT_OK, intent);
		finish();
	}
}
